package com.yami.shop.app.controller;

import com.yami.shop.app.utils.HttpResult;
import com.yami.shop.bean.model.Category;
import com.yami.shop.bean.model.Product;
import com.yami.shop.security.util.SecurityUtils;
import com.yami.shop.service.CategoryService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Random;

@RestController
@RequestMapping("/app/goods")
@Api(tags = "商品管理接口")
public class GoodsController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 商品分类
     */
    @PostMapping("/getGoodsType")
    public  HttpResult getGoodsType(){
        Long shopId =  SecurityUtils.getSysUser().getShopId();
        //获取商品分类
        List<Category> categoryList = categoryService.getAllCategory(shopId);
        return HttpResult.success(categoryList);
    }


    /**
     * 新增商品
     */
    @PostMapping("/addNewGoods")
    public HttpResult addNewGoods(Product product){

        return HttpResult.success();
    }

    /**
     * 条形码
     */
    @PostMapping("/producceBarCode")
    public HttpResult producceBarCode(){
        String base = "0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < 13; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return  HttpResult.success(sb.toString());
    }

}
